package com.google.monkeyjump;

import util.Constants;

import com.google.monkeyjump.db.DataBaseAdapter;
import com.google.monkeyjump.ranking.Rank;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class SaveRankActivity extends Activity{

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.save_rank);
		
		int score = getIntent().getIntExtra(Constants.RANK_SAVE_ACTIVITY_SCORE_ID, 0);
		
		final Rank rank = new Rank();
		rank.setPoints(score);
		
		((TextView) super.findViewById(R.id.rankMonkey)).setText(rank.getClassification().name());
		((TextView) super.findViewById(R.id.rankScore)).setText(String.valueOf(rank.getPoints()));
		
		Button saveButton = (Button) super.findViewById(R.id.rankSave);
		saveButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				rank.setUser(((TextView) SaveRankActivity.this.findViewById(R.id.rankName)).getText().toString());
				DataBaseAdapter.getInstance().addRank(rank);
				SaveRankActivity.this.finish();
				Intent rank = new Intent(SaveRankActivity.this, RankListActivity.class);
                startActivity(rank);
			}
		});
		
	}
}
